package com.party.admin.web.controller.dataAnalyze;

import com.party.admin.biz.dataAnalyze.DataAnalyzeBizService;
import com.party.admin.web.dto.input.dataAnalyze.DataAnalyzeInput;
import com.party.admin.web.dto.output.dataAnalyze.DataAnalyzeOutput;
import com.party.common.utils.StringUtils;
import com.party.core.model.member.MemberWithPartner;
import com.party.core.service.member.IMemberGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * @Description: 运营功能-数据分析
 * @Author: yangshoukun
 * @Date: 2018/6/26 17:37
 */
@Controller
@RequestMapping("/data/analyze")
public class DataAnalyzeController {

    @Autowired
    private DataAnalyzeBizService dataAnalyzeBizService;

    @Autowired
    private IMemberGroupService memberGroupService;

    @RequestMapping("list")
    public ModelAndView list(DataAnalyzeInput input) {
        ModelAndView mv = new ModelAndView("dataAnalyze/dataAnalyze");

        List<Map<String, String>> modules = dataAnalyzeBizService.getTypes();

        if (StringUtils.isNotEmpty(input.getModuleCode())) {
            for (Map<String, String> module : modules) {
                String code = module.get("code");
                if (code.equals(input.getModuleCode())) {
                    input.setModuleValue(module.get("value"));
                    break;
                }
            }
        }

        List<MemberWithPartner> partnerList = memberGroupService.getAllPartnersSelectlist();
        mv.addObject("partnerList", partnerList);

        List<DataAnalyzeOutput> list = dataAnalyzeBizService.list(input);

        mv.addObject("list", list);
        mv.addObject("modules", modules);
        mv.addObject("input", input);
        return mv;
    }
}
